
#include "../SRC/DF_Common/basis_state.h"
#include "../SRC/DF_Common/com_sparse_row.h"
#include "../SRC/DF_Common/coupling_coeff.h" 
#include "../SRC/DF_Common/read_data.h"
#include "../SRC/DF_Common/time_count.h"
#include "../SRC/DF_Local/multi_pack.h"
#include "../SRC/DF_Local/normal_order.h"
#include "../SRC/DF_Local/package.h"
#include "../SRC/DF_Local/serial_multi_control.h"

#include <boost/filesystem.hpp>
#include <cmath>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>

// using std::cin;
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
namespace bf = boost::filesystem;
// using namespace std;

int main() {

  Time_Count TC_main;
  TC_main.start();
  LEC_CONST LECs;
  const std::string path_out = "serial_dat/Output_MP";
  // bf::path path(path_s);
  if (!bf::exists(path_out)) {
    bf::create_directory(path_out);
  }
  //~~~~~~~~~~~~~~~~ basis ~~~~~~~~~~~~~~~~~~~//
  Serial_SL ser_t;
  Serial_Multi_SL ser_mul_t;
  SMatrix_Ch mat_s_ch;
  Multi_Pack mulpack;
  mulpack.print_General();
  int save_flag = 1;
  cout << "Multi_Pack save ? 1:yes 2:load" << endl;
  //cin >> save_flag;

  cout << "save_flag = " << save_flag << endl;
  if (save_flag == 1) {
    // string file_A = "Output_A_Nav_ext8";
    // string file_B = "Output_B_Nav_ext8";
    // string file_A = "Output_A_fir_pf";
    // string file_B = "Output_B_fir_pf";
    string file_A;
    string file_B;
    std::ifstream AB_file;
    AB_file.open("data/Input/AB_file.Input");
    AB_file >> file_A;
    char u_x[256];
    AB_file.getline(u_x, 256, '\n');
    AB_file >> file_B;
    AB_file.close();

    cout << "\t FILE_A : " << file_A << endl;
    cout << "\t FILE_B : " << file_B << endl;
    mulpack.init(file_A, file_B);
    mulpack.build_S();
    cout << " ### mulpack.Emax = " << mulpack.E_max << endl;
    ser_mul_t.save(mulpack, "serial_dat/Output_MP/mulpack_serial.dat");
  } else if (save_flag == 2) {
    ser_mul_t.load(mulpack, "serial_dat/Output_MP/mulpack_serial.dat");
  }
  cout << "Start mulpack.print " << endl;
  mulpack.print("serial_dat/Output_MP/Multi_pack.dat");
  cout << "Start mulpack.print_Tz " << endl;
  mulpack.print_Tz("serial_dat/Output_MP/Multi_pack_Tz.dat");
  cout << endl;
  std::string Pack_ALL_File_name = "serial_dat/Output_MP/3BME_DF.dat";
  std::ofstream Pack_ALL_File;
  Pack_ALL_File.open(Pack_ALL_File_name);
  mulpack.print_General(Pack_ALL_File);
  cout<<"Start to Output"<<endl;
  mulpack.print_TP_ALL_f(Pack_ALL_File);
  Pack_ALL_File.close();
  cout << "  --- Generate 3BME succeffully in " << Pack_ALL_File_name
       << "  ---- " << endl;
  cout << " === Finished Multi Pack === " << endl;
  /*
  CheckVsSat check_sat(mulpack.SP,mulpack.TP, mulpack);
  check_sat.control();/**/
}
